package com.tamartech.greendb.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;

import org.apache.log4j.Logger;

import com.Ostermiller.util.CSVParser;
import com.Ostermiller.util.LabeledCSVParser;

// class to initially import Jonathan's spreadsheet. Unlikely ever to need it again
public class PostalVoterFilter_old
{
    private static Logger logger = Logger.getLogger (PostalVoterFilter_old.class);
    
    private static final int POSTAL_COL = 22;
    
	public static void main(String[] args) throws Exception
	{
        File inFile = new File (args[0] + ".CSV");
        File outFile = new File (args[0] + "-postal.csv");
	    
        LabeledCSVParser csv = new LabeledCSVParser (new CSVParser (new FileInputStream (inFile)));
        PrintWriter out = new PrintWriter (outFile);
        
        for (;;)
        {
            String[] line = csv.getLine();
            
            if (line != null)
                logger.info(line[0] + line[1]);
            
            if (line == null)
                break;
            
            if (line.length < 23 || !line[POSTAL_COL].trim().equals("Postal"))
                continue;
            
            StringBuffer outLine = new StringBuffer();
            
            outLine.append(line[0] + ",");
            outLine.append(line[1] + ",");
            outLine.append(line[2] + ",");
            outLine.append(line[4] + ",");
            outLine.append(line[5] + ",");
            outLine.append(line[12] + ",");
            outLine.append(line[13] + ",");
            outLine.append(line[14] + ",");
            outLine.append(line[15] + ",");
            outLine.append(line[16] + ",");
            outLine.append(line[21] + ",");
            outLine.append(line[22] + ",");
            
            out.println (outLine.toString());
        }
        
        csv.close();
        out.close();

	}
	
} 